const db = uniCloud.database();
export default {
	data() {
		return {
			userInfo: this.$store.state.login || {},
			chartData: {}, // 您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
			opts: {
				color: ["#FAC858", "#73C0DE", "#1890FF", "#ea7ccc", "#EE6666", "#91CB74", "#FC8452"],
				padding: [15, 10, 0, 15],
				enableScroll: false,
				legend: {
					float: 'left',
					fontSize: 12,
					fontColor: '#909399',
					lineHeight: 16,
					itemGap: 16
				},
				xAxis: {
					disableGrid: true,
					title: "日",
					titleOffsetX: 10
				},
				yAxis: {
					disabled: false,
					disableGrid: false,
					splitNumber: 5,
					gridType: "dash",
					dashLength: 4,
					gridColor: "#CCCCCC",
					padding: 10,
					showTitle: true,
					data: [{
							position: "left",
							title: "数量",
							tofix: 0,
							textAlign: "right",
							titleOffsetY: -5,
							titleOffsetX: -16
						},
						{
							position: "right",
							title: "￥",
							tofix: 1,
							textAlign: "left",
							titleOffsetY: -5,
							titleOffsetX: 8
						}
					]
				},
				extra: {
					mix: {
						column: {
							width: 20
						}
					}
				}
			}
		}
	},
	async onLoad() {
		this.getSevenDay();
	},
	async onShow() {},
	async onPullDownRefresh() {
		uni.stopPullDownRefresh();
	},
	methods: {
		async getSevenDay() {
			const getSevenRes = await this.$uniCloudCallFunction({
				name: "xxf-manager",
				action: "getSevenDayList",
				data: {
					uid: this.$store.state.login.uid,
				}
			});
			console.log("getSevenRes: ", getSevenRes);
			let chartRes = {
				categories: getSevenRes.sevenDays,
				series: [{
					name: "营业额",
					index: 1,
					type: "column",
					data: getSevenRes.sevenMoney
				}, {
					name: "日下单量",
					type: "line",
					style: "curve",
					data: getSevenRes.sevenAllOrders
				}, {
					name: "日成交量",
					type: "line",
					style: "curve",
					data: getSevenRes.sevenOrders
				}, {
					name: "日销产品数",
					type: "line",
					style: "curve",
					data: getSevenRes.sevenPros
				}, {
					name: "日退款量",
					type: "line",
					style: "curve",
					data: getSevenRes.sevenRefund
				}, ]
			};
			this.chartData = JSON.parse(JSON.stringify(chartRes));
		},
		toShipping() {
			uni.navigateTo({
				url: "/pages/managerPack/shipping/index"
			})
		},
		toALL() {
			uni.navigateTo({
				url: "/pages/managerPack/allList/index"
			})
		},
		toDo() {
			this.$utils.showToast(this, {
				message: '暂未开放权限，请联系超管！',
			});
		},
		async doDataScript() {
			if (this.userInfo.uid === '6753b77b40541824a6e20fee') {
				const doRes = await this.$uniCloudCallFunction({
					name: 'xxf-manager',
					action: 'doDataScript',
					data: {
						uid: this.$store.state.login.uid,
					}
				});
				console.log("doRes: ", doRes);
				if (doRes) {
					console.log('更新成功', doRes);
					this.$utils.showToast(this, {
						message: '更新成功！',
						mode: 1
					});
				} else {
					console.error('更新失败', doRes);
				}
			} else {
				this.$utils.showToast(this, {
					message: '暂未开放权限，请联系超管！',
				});
			}
		}
	}
}